package com.sword.ms_bwk;

import com.sword.ms_bwk.furniture.AbstractFurnitureWithProperty;
import com.sword.ms_bwk.block.FurnitureBlock;
import com.sword.ms_bwk.furniture.*;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class ObjectInitialization {
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Utils.MOD_ID);
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Utils.MOD_ID);
    public static final DeferredRegister<BlockEntityType<?>> TILE_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, Utils.MOD_ID);
    public static final DeferredRegister<SoundEvent> SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, Utils.MOD_ID);



    public static final NormalBlockOfInit WOOD_GRAIN = register("wood_grain");
    public static final NormalBlockOfInit WOOD_GRAIN_SLANT = register("wood_grain_slant");
    public static final NormalBlockOfInit WALL_TEXTURE = register("wall_texture");
    public static final NormalBlockOfInit CEILING_TEXTURE = register("ceiling_texture");

    public static final FurnitureBlockOfInit BRIDGE = register(new Bridge());
    public static final FurnitureBlockOfInit CABINET = register(new Cabinet());
    public static final FurnitureBlockOfInit CEILING = register(new Ceiling());
    public static final FurnitureBlockOfInit CEILING_LIGHT = register(new CeilingLight());
    public static final FurnitureBlockOfInit CEILING_CORNER = register(new CeilingCorner());
    public static final FurnitureBlockOfInit CEILING_GROOVE = register(new CeilingGroove());
    public static final FurnitureBlockOfInit CHAIR1 = register(new Chair1());
    public static final FurnitureBlockOfInit CHAIR2 = register(new Chair2());
    public static final FurnitureBlockOfInit COOKING_BENCH = register(new CookingBench());
    public static final FurnitureBlockOfInit ORNAMENT = register(new Ornament());
    public static final FurnitureBlockOfInit OVEN = register(new Oven());
    public static final FurnitureBlockOfInit PENDENT_LAMP = register(new PendentLamp());
    public static final FurnitureBlockOfInit DISHWASHER = register(new Dishwasher());
    public static final FurnitureBlockOfInit RANGE_HOOD = register(new RangeHood());
    public static final FurnitureBlockOfInit RECEPTION = register(new Reception());
    public static final FurnitureBlockOfInit RECEPTION_CORNER = register(new ReceptionCorner());
    public static final FurnitureBlockOfInit RECEPTION_SHORT = register(new ReceptionShort());
    public static final FurnitureBlockOfInit TRACK_LIGHT1 = register(new TrackLight1());
    public static final FurnitureBlockOfInit TRACK_LIGHT2 = register(new TrackLight2());
    public static final FurnitureBlockOfInit TRACK_LIGHT3 = register(new TrackLight3());
    public static final FurnitureBlockOfInit TRACK_LIGHT4 = register(new TrackLight4());
    public static final FurnitureBlockOfInit VENTILATION_FAN = register(new VentilationFan());
    public static final FurnitureBlockOfInit WASHING_TABLE = register(new WashingTable());



    //普通方块注册方法
    private static NormalBlockOfInit register(final String name) {
        return new NormalBlockOfInit(name);
    }

    //家具方块专用注册方法
    private static FurnitureBlockOfInit register(final AbstractFurnitureWithProperty furniture) {
        return new FurnitureBlockOfInit(furniture);
    }

    //普通方块注册类
    public static class NormalBlockOfInit {
        public final RegistryObject<Block> block;
        public final RegistryObject<Item> item;

        public NormalBlockOfInit(String name) {
            block = BLOCKS.register(name, () -> new Block(BlockBehaviour.Properties.of(Material.STONE)));
            item = ITEMS.register(name, () -> new BlockItem(block.get(), new Item.Properties().tab(FurnitureGroup.FURNITURE_GROUP)));
        }
    }

    //家具方块专用注册类
    public static class FurnitureBlockOfInit {
        public final RegistryObject<Block> block;
        public final RegistryObject<Item> item;

        public FurnitureBlockOfInit(AbstractFurnitureWithProperty furniture) {
            block = BLOCKS.register(furniture.name, () -> new FurnitureBlock(furniture));
            item = ITEMS.register(furniture.name, () -> new BlockItem(block.get(), new Item.Properties().tab(FurnitureGroup.FURNITURE_GROUP)));
        }
    }

}
